package cn.yunhe.service.impl;

import cn.yunhe.dao.IUserDao;
import cn.yunhe.entity.User;
import cn.yunhe.service.IUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("userService")
public class UserServiceImpl implements IUserService {


    @Resource
    private IUserDao userDao;

    @Override
    public Page getLikeUsers(Map<String, Object> cond) {
        Page page=new Page();
        //查询符合条件的记录总数，赋值给
        page.setTotal(userDao.getCount(cond));

        //每一页大小
        int pageSize=Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);
        //当前页
        int pageNum=Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setPageNum(pageNum);

        //总页数
        page.setPageNum((int) (page.getTotal()/pageSize+(page.getTotal()%pageSize==0?0:1)));

        page=PageHelper.startPage(pageNum,pageSize);
        List<User> list= userDao.getLikeUsers(cond);


        return page;
    }

    @Override
    public User selectByPrimary(int userId) {
        return userDao.selectByPrimary(userId);
    }

    @Override
    public List<User> selectAll() {
        return userDao.selectAll();
    }

    @Override
    public int addUser(User user) {
        return userDao.addUser(user);
    }

    @Override
    public int delUser(User user) {
        return userDao.delUser(user);
    }

    @Override
    public Integer selectByNameAndPass(User user) {
        return userDao.selectByNameAndPass(user);
    }

    @Override
    public User getUser(User user) {
        return userDao.getUser(user);
    }

    @Override
    public void editUser(User user) {

        userDao.editUser(user);
    }


    public IUserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(IUserDao userDao) {
        this.userDao = userDao;
    }
}
